/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */

package l1j.server.server.serverpackets;

import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.gametime.L1GameTimeClock;
import l1j.server.server.utils.IntRange;

public class S_OwnCharStatus extends ServerBasePacket {
	private static final String S_OWB_CHAR_STATUS = "[S] S_OwnCharStatus";
	private  final IntRange hpRange = new IntRange(1, 32767);
	private  final IntRange ValueRange = new IntRange(1, 255);
	private  final IntRange acRange = new IntRange(-211, 10);
	private byte[] _byte = null;

	public S_OwnCharStatus(final L1PcInstance pc) {
		int time = L1GameTimeClock.getInstance().currentTime().getSeconds();
		time = time - (time % 300);
		// _log.warning((new
		// StringBuilder()).append("送信時間:").append(i).toString());
		this.writeC(S_OPCODE_OWNCHARSTATUS);
		this.writeD(pc.getId());
		this.writeC(pc.getLevel());
		this.writeExp(pc.getExp());
		this.writeC(ValueRange.ensure(pc.getStr()));
		this.writeC(ValueRange.ensure(pc.getInt()));
		this.writeC(ValueRange.ensure(pc.getWis()));
		this.writeC(ValueRange.ensure(pc.getDex()));
		this.writeC(ValueRange.ensure(pc.getCon()));
		this.writeC(ValueRange.ensure(pc.getCha()));
		if(pc.getConfig().isHpBarRateX10()){
			this.writeH(hpRange.ensure(pc.getCurrentHp()));
			this.writeH(hpRange.ensure(pc.getMaxHp()));
		}else{
			this.writeH(hpRange.ensure(pc.getCurrentHp()/10));
			this.writeH(hpRange.ensure(pc.getMaxHp()/10));
		}
		this.writeH(hpRange.ensure(pc.getCurrentMp()));
		this.writeH(hpRange.ensure(pc.getMaxMp()));
		this.writeC(acRange.ensure(pc.getAc()));
		this.writeD(time);
		this.writeC(pc.get_food());
		this.writeC(pc.getInventory().getWeight240());
		this.writeH(pc.getLawful());
		this.writeC(pc.getFire());
		this.writeC(pc.getWater());
		this.writeC(pc.getWind());
		this.writeC(pc.getEarth());
	}

	@Override
	public byte[] getContent() {
		if (this._byte == null) {
			this._byte = this._bao.toByteArray();
		}
		return this._byte;
	}

	@Override
	public String getType() {
		return S_OWB_CHAR_STATUS;
	}
}